<template>
    <a-collapse v-model="panelActiveKeys" accordion>
        <a-collapse-panel key="globalVars" :header="i18n('globalVars','全局变量')">
            <div v-if="vars.length!=0" style="height:350px;overflow:scroll;">
                <a-row v-for="index of arrLen" :key="index">
                    <a-col :span="12">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <span solt="label">
                                {{$i18(vars[2 * index - 2].desc,"国际化变量名称")}}
                                (<span>{{vars[2 * index - 2].name}}</span>)
                            </span>
                            <a-input :disabled="vars[2 * index - 2].isEdit!='YES'" v-model="globalVars[vars[2 * index - 2].name]" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="12" v-if="vars[2 * index - 1]">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <span solt="label">
                                {{$i18(vars[2 * index - 1].desc,"国际化变量名称")}}
                                (<span>{{vars[2 * index - 1].name}}</span>)
                            </span>
                            <a-input :disabled="vars[2 * index - 1].isEdit!='YES'" v-model="globalVars[vars[2 * index - 1].name]" />
                        </a-form-item>
                    </a-col>
                </a-row>
            </div>
        </a-collapse-panel>
        <a-collapse-panel key="customVar" :header="i18n('customVar','自定义变量')">
            <div class="table-operator">
                <a-button type="primary" @click="addCustom">{{i18n('addCustom','添加变量')}}</a-button>
                <a-button type="danger" @click="removeCustom">{{i18n('removeCustom','删除变量')}}</a-button>
            </div>
            <rx-grid ref="customVar" :dataSource="customVars" :allowRowSelect="true" :multiSelect="true"
                     :showPage="false" :columns="varsColumns"
                     style="min-height: 350px">
                <span slot="name" slot-scope="{text,record,index}">
                    <a-input v-model="record.name" />
                </span>
                <span slot="value" slot-scope="{text,record,index}">
                    <a-input v-model="record.value" />
                </span>
                <span slot="desc" slot-scope="{text,record,index}">
                    <a-input v-model="record.desc" />
                </span>
            </rx-grid>
        </a-collapse-panel>
        <a-collapse-panel key="genFile" :header="i18n('genFile','生成文件')">
            <rx-grid ref="genFile" :dataSource="files" :allowRowSelect="false"
                     :showPage="false" :columns="fileColumns"
                     style="min-height: 350px">
                <span slot="templateFile" slot-scope="{text,record,index}">
                    <a-select style="width: 100%;" v-model="record.templateFile" :options="templateTypeFiles[record.templateType]" @change="changeFile($event,record)" />
                </span>
                <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                    <span v-if="record.templateFile" @click="editFile(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                    <span v-if="record.templateFile" @click="reloadFile(record)">{{i18n('reloadFile','还原')}}</span>
                </span>
            </rx-grid>
        </a-collapse-panel>
    </a-collapse>
</template>

<script>
    import FormCodegenBusinessEdit4 from "./FormCodegenBusinessEdit4.js";

    export default {
        name: "FormCodegenBusinessEdit4",
        mixins:[FormCodegenBusinessEdit4],
        methods:{
            i18n(name,text,key){
                return this.$ti18(name,text,"formCodegenBusiness.edit4",key);
            },
            handleBefore(self, this_){
                var result=this_.getData();
                Object.assign(this_.settingJson,result.data);
                this_.formData.settingJson = JSON.stringify(this_.settingJson);
                this_.$emit("changeForm", this_.formData);
            },
            handleSubmit(self, this_,callback){
                var result = this_.getData();
                if (!result.success) {
                    this_.$message.warning(result.message);
                    return callback(true);
                }
                Object.assign(this_.settingJson,result.data);
                this_.formData.settingJson = JSON.stringify(this_.settingJson);
                this_.$emit("changeForm", this_.formData);
                callback(false);
            }
        }
    }
</script>

<style scoped>

</style>